package com.zheng.shop.rpc.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zheng.common.annotation.BaseService;
import com.zheng.common.base.BaseServiceImpl;
import com.zheng.shop.common.exception.ShopException;
import com.zheng.shop.dao.mapper.ShopParamMapper;
import com.zheng.shop.dao.model.ShopParam;
import com.zheng.shop.rpc.api.ShopParamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zheng.common.annotation.BaseService;
import com.zheng.common.base.BaseServiceImpl;
import com.zheng.shop.dao.mapper.ShopParamMapper;
import com.zheng.shop.dao.model.ShopParam;
import com.zheng.shop.rpc.api.ShopParamService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author likun
 * @since 2017-12-29
 */
@Service
@Transactional(rollbackFor = ShopException.class)
@BaseService
public class ShopParamServiceImpl extends BaseServiceImpl<ShopParamMapper, ShopParam> implements ShopParamService {
    @Autowired
    ShopParamMapper shopParamMapper;

    @Override
    public boolean copyParam(Integer productCategoryId, List<Integer> paramIdList) throws ShopException {
        for (Integer id : paramIdList) {
            ShopParam param = selectById(id);
            param.setId(null);
            param.setCategoryId(productCategoryId);
            if (!insert(param)) {
                throw new ShopException("复制参数失败！");
            }
        }
        return true;
    }

    @Override
    public List<ShopParam> getParamByProductCategoryId(Integer productCategoryId) {
        EntityWrapper<ShopParam> paramEntityWrapper = new EntityWrapper<>();
        paramEntityWrapper.where("category_id=" + productCategoryId);
        return selectList(paramEntityWrapper);
    }
}
